# 对战系统编写
import time
import random


class renwu:  # 人物数值初始化
    data = {}
    def __init__(self, name, blood, defend, attack,akd_times= 0):
        # 定义人物的 名字 血量 防御 攻击力 被攻击的时间
        self.attack = attack
        self.name = name
        self.blood = blood
        self.defend = defend
        self.akd_times = akd_times
        print(name, "初始化成功")

    def daji_fangshi(self, other):
        # 攻击方式
        print(self.name, "正在攻击 ->", other.name)
        a = random.randint(1, 10)
        if a == 2:
            print(self.name, "产生了暴击")
            other.blood = other.blood + other.defend - self.attack * 2
            print(other.name, "血量剩余：", other.blood)
        elif a == 4:
            print(self.name, "产生暴击")
            other.blood = other.blood + other.defend - self.attack * 2
            print(other.name, "血量剩余：", other.blood)
        elif a == 8:
            print(self.name,"闪避攻击")
            other.blood = other.blood
            print(other.name, "血量剩余：", other.blood)
        elif a == 3:
            print(self.name,"闪避攻击")
            other.blood = other.blood
            print(other.name, "血量剩余：", other.blood)
        else:
            other.blood = other.blood + other.defend - self.attack
            print(other.name, "血量剩余：", other.blood)

        # 存入字典
        self.akd_times += 1
        self.data[self.akd_times] = other.blood
        print(self.data)


        return other.blood

    # 数据存入字典
    def storage(self,other):
        database_one = {} # 菜狗1
        database_tow = {} # 菜狗2
        biaozhi = True
        while biaozhi :
            other.data[i] = other.blood

if __name__ == '__main__':
    i = 0
    e = 0
    dog2 = 0
    dog_2 = 0

    # 使人物数值随机产生
    xueliang_1 = random.randint(50,101) # 血量
    fangyu_1 = random.randint(1,11) # 防御
    gongji_1 = random.randint(1,20) # 攻击

    xueliang_2 = random.randint(50, 101)  # 血量
    fangyu_2 = random.randint(1, 11)  # 防御
    gongji_2 = random.randint(1, 20)  # 攻击

    b = renwu("菜狗 1",xueliang_1,fangyu_1,gongji_1)
    c = renwu("菜狗 2",xueliang_2,fangyu_2,gongji_2)


    while 1:
        print("-------------------------------------------")
        time.sleep(1)
        if i == e:
            i = i + 1
            print("菜狗2的攻击次数为：", i)
        e = e + 1
        b_blood = c.daji_fangshi(b)
        if b_blood <= 0:
            b_blood == 0
            print(b.name, "挂了")
            break

        print("-------------------------------------------")
        time.sleep(1)
        if dog2 == dog_2:
            dog2 = dog2 + 1
            print("菜狗1的攻击次数为：", dog2)
        dog_2 = dog_2 + 1
        c_blood = b.daji_fangshi(c)
        if c_blood <= 0:
            c_blood == 0
            print(c.name, "挂了")
            break
